using System;
using System.CodeDom.Compiler;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Input;
using System.Windows.Markup;
using System.Windows.Media;
using System.Windows.Shapes;
using Common;
using Common.Enum;
using Common.NotifyEvent;
using Controls;
using CustomChart;
using Define;
using MainView.MainControls;
using MainView.MainControls.Chart;
using MainView.Windows;
using SExperiment;
using SExperiment.ExperimentResult;
using SProject;
using SProject.BasicInformation;
using SProject.Program;
using SSettings;
using SSettings.SoftSetting;
using SWellPlate;

namespace MainView.View
{
	public partial class UCExperimentRun : UserControl, IDisposable, IComponentConnector
	{
		public static readonly DependencyProperty MaxXProperty = DependencyProperty.Register("MaxX", typeof(double?), typeof(UCExperimentRun), new UIPropertyMetadata(2.0));

		public static readonly DependencyProperty CurveMaxYModeProperty = DependencyProperty.Register("CurveMaxYMode", typeof(ECurveMaxYMode), typeof(UCExperimentRun), new UIPropertyMetadata(ECurveMaxYMode.AllWells, OnCurveMaxYModeChanged));

		private Experiment _Experiment;

		private bool isLoad;

		private bool[] _NeedRefreshCurve = new bool[5];

		private bool _StopRefresh;

		private bool updataCurveFlag = true;

		public double? MaxX
		{
			get
			{
				return (double?)GetValue(MaxXProperty);
			}
			set
			{
				SetValue(MaxXProperty, value);
			}
		}

		public ECurveMaxYMode CurveMaxYMode
		{
			get
			{
				return (ECurveMaxYMode)GetValue(CurveMaxYModeProperty);
			}
			set
			{
				SetValue(CurveMaxYModeProperty, value);
			}
		}

		private static void OnCurveMaxYModeChanged(object sender, DependencyPropertyChangedEventArgs args)
		{
			UCExperimentRun uCExperimentRun = sender as UCExperimentRun;
			if (uCExperimentRun != null)
			{
				uCExperimentRun.RefreshChartInfo(false);
			}
		}

		public UCExperimentRun(Experiment experiment)
		{
			_Experiment = experiment;
			_Experiment.Event += _Experiment_Event;
			_Experiment.Device.RunMeltingSegmentEvent += Device_RunMeltingSegmentEvent;
			_Experiment.Device.StatusUpdateEvent += Device_StatusUpdateEvent;
			base.DataContext = _Experiment;
			InitializeComponent();
			UCWellPlateRun.SetBinding(UCPlate.WellSelectModeProperty, new Binding("WellSelectMode")
			{
				Source = _Experiment.ExperimentSetting
			});
			UCWellPlateRun.SetBinding(UCPlate.PressCtlCanSelectWellProperty, new Binding("PressCtlCanSelectWell")
			{
				Source = _Experiment.ExperimentSetting
			});
			UCWellPlateRun.Experiment = _Experiment;
			UCWellPlateRun.SetBinding(UCPlate.HighLightProperty, new Binding("HighLight")
			{
				Source = _Experiment.ExperimentSetting
			});
			UCWellInfoRun.SetBinding(UCWellInfo.HighLightProperty, new Binding("HighLight")
			{
				Source = _Experiment.ExperimentSetting
			});
			UCChartRunRaw.SetBinding(BaseCurveChart.HighLightProperty, new Binding("HighLight")
			{
				Source = _Experiment.ExperimentSetting
			});
			UCChartRunAMP.SetBinding(BaseCurveChart.HighLightProperty, new Binding("HighLight")
			{
				Source = _Experiment.ExperimentSetting
			});
			UCChartRawMelt.SetBinding(BaseCurveChart.HighLightProperty, new Binding("HighLight")
			{
				Source = _Experiment.ExperimentSetting
			});
			UCChartRunRaw.SetBinding(BaseCurveChart.CurverWidthProperty, new Binding("CurverWidth")
			{
				Source = _Experiment.ExperimentSetting
			});
			UCChartRunAMP.SetBinding(BaseCurveChart.CurverWidthProperty, new Binding("CurverWidth")
			{
				Source = _Experiment.ExperimentSetting
			});
			UCChartRawMelt.SetBinding(BaseCurveChart.CurverWidthProperty, new Binding("CurverWidth")
			{
				Source = _Experiment.ExperimentSetting
			});
			UCChartRunAMP.SetBinding(BaseCurveChart.ThresholdVisibleProperty, new Binding("AMPCurveDisplayThreshold")
			{
				Source = _Experiment.ExperimentSetting,
				Mode = BindingMode.TwoWay
			});
			UCChartRunRaw.SetBinding(BaseCurveChart.ShowCurveToolTipsProperty, new Binding("ShowCurveToolTips")
			{
				Source = _Experiment.ExperimentSetting
			});
			UCChartRunAMP.SetBinding(BaseCurveChart.ShowCurveToolTipsProperty, new Binding("ShowCurveToolTips")
			{
				Source = _Experiment.ExperimentSetting
			});
			UCChartRawMelt.SetBinding(BaseCurveChart.ShowCurveToolTipsProperty, new Binding("ShowCurveToolTips")
			{
				Source = _Experiment.ExperimentSetting
			});
			UCWellInfoRun.Targets = UCWellPlateRun.WellTargets;
			UCChartRunAMP.Targets = UCWellPlateRun.WellTargets;
			UCChartRunRaw.Targets = UCWellPlateRun.WellTargets;
			gridColor.SetBinding(FrameworkElement.DataContextProperty, new Binding("ColorSettings")
			{
				Source = ConfigSettings.GetInstance().ExperimentSetting
			});
			RefreshCurve();
			InitPCRProgramMenu();
			RefreshComboBoxDisplayMode();
			RefreshChartSample();
			SetRunStatus();
			AddHandler(BaseCurveChart.OnLineColorChangedRoutedEvent, new RoutedEventHandler(OnLineColorChanged_RoutedEvent), true);
			AddHandler(UCWellInfo.OnSelectionChangedRoutedEvent, new RoutedEventHandler(OnSelectionChanged_RoutedEvent), true);
			AddHandler(UCPlate.OnSelectionChangedRoutedEvent, new RoutedEventHandler(WellPlateSelectionChanged_RoutedEvent), true);
		}

		public NormalChart GetRawChart()
		{
			return UCChartRunRaw.UltraChart;
		}

		public UCTemperatureChart GetTemperatureChart()
		{
			return ucTemperatureChart;
		}

		private void RefreshComboBoxDisplayMode()
		{
			List<KeyValuePair> list = new List<KeyValuePair>(EnumManagement.GetAllColorMode());
			if (_Experiment.Type == EProjectType.HRM)
			{
				list = list.Where((KeyValuePair s) => (EColorMode)s.Key == EColorMode.Type).ToList();
			}
			else if (_Experiment.Type == EProjectType.AD)
			{
				list = list.Where((KeyValuePair s) => (EColorMode)s.Key == EColorMode.Type || (EColorMode)s.Key == EColorMode.Channel || (EColorMode)s.Key == EColorMode.Target).ToList();
			}
			else
			{
				KeyValuePair keyValuePair = list.Where((KeyValuePair s) => (EColorMode)s.Key == EColorMode.Result).FirstOrDefault();
				if (keyValuePair != null)
				{
					list.Remove(keyValuePair);
				}
			}
			comboDisplayMode.ItemsSource = list;
		}

		private void _Experiment_Event(object sender, EventArgs e)
		{
			PropertyChangedEventArgsEx propertyChangedEventArgsEx = e as PropertyChangedEventArgsEx;
			if (propertyChangedEventArgsEx == null)
			{
				return;
			}
			if (propertyChangedEventArgsEx.PropertyName == "Type")
			{
				UCWellInfoRun.RefreshData();
			}
			else if (propertyChangedEventArgsEx.PropertyName == "Program")
			{
				if (updataCurveFlag)
				{
					RefreshCurve();
				}
			}
			else if (propertyChangedEventArgsEx.PropertyName == "ColorMode")
			{
				RefreshChartSample();
			}
		}

		public void Dispose()
		{
			ucTemperatureChart.Dispose();
			UCWellInfoRun.Dispose();
			foreach (TabItem item in (IEnumerable)TabControlCurve.Items)
			{
				if (item.Content is BaseCurveChart)
				{
					((BaseCurveChart)item.Content).Dispose();
				}
			}
		}

		private void OnLineColorChanged_RoutedEvent(object sender, RoutedEventArgs e)
		{
			RefreshChartSample();
		}

		private void Root_Loaded(object sender, RoutedEventArgs e)
		{
			if (!isLoad)
			{
				isLoad = true;
				UCWellPlateRun.SelectAll();
			}
		}

		private void Device_StatusUpdateEvent(object sender, EventArgs e)
		{
			tbRunning.Text = _Experiment.Device.Running;
			tbRunningTime.Text = _Experiment.Device.RunningTime.ToString().Substring(0, 8);
			tbRemainTime.Text = _Experiment.Device.RemainTime.ToString().Substring(0, 8);
			tbCycles.Text = _Experiment.Device.Cycles.ToString();
			tbHotlidTemperature.Text = ((_Experiment.UseHotBonnet || ConfigReader.GetInstance().GetShowHotlidTemperature()) ? _Experiment.Device.CurrentHotlidTemperature.ToString("00.0℃") : Utility.GetMessage("NA"));
			tbSetTemperature.Text = _Experiment.Device.SetTemperature.ToString("00.0℃");
			tbCurrentBlockTemperature.Text = ((ConfigReader.GetInstance().GetShowHotlidTemperature() || _Experiment.TemperatureControlMode == ETemperatureControlMode.Module || _Experiment.TemperatureControlMode == ETemperatureControlMode.Tube) ? _Experiment.Device.CurrentBlockTemperature.ToString("00.00℃") : Utility.GetMessage("NA"));
			tbHoldingTimeMinute.Text = _Experiment.Device.HoldingTimeMinute.ToString("00");
			tbHoldingTimeSecond.Text = _Experiment.Device.HoldingTimeSecond.ToString("00");
			tbCurrentTubeTemperature.Text = ((ConfigReader.GetInstance().GetShowHotlidTemperature() || _Experiment.TemperatureControlMode == ETemperatureControlMode.Tube || _Experiment.TemperatureControlMode == ETemperatureControlMode.Fast) ? _Experiment.Device.CurrentTubeTemperature.ToString("00.00℃") : Utility.GetMessage("NA"));
		}

		private void Device_RunMeltingSegmentEvent(object sender, EventArgs e)
		{
			if (tabItemRawMeltCurve.Visibility == Visibility.Visible)
			{
				tabItemRawMeltCurve.IsSelected = true;
			}
		}

		private void RefreshCurve()
		{
			if (_Experiment.Program == null)
			{
				tabItemRawCurve.Visibility = Visibility.Collapsed;
				tabItemAMPCurve.Visibility = Visibility.Collapsed;
				tabItemRawMeltCurve.Visibility = Visibility.Collapsed;
			}
			else
			{
				tabItemRawCurve.Visibility = ((_Experiment.Program.GetAcquisitionCycleCount() <= 0) ? Visibility.Collapsed : Visibility.Visible);
				tabItemAMPCurve.Visibility = tabItemRawCurve.Visibility;
				tabItemRawMeltCurve.Visibility = ((_Experiment.Program.Programs.Where((BaseSegment s) => s is MeltingSegment).Count() == 0) ? Visibility.Collapsed : Visibility.Visible);
				UCChartRawMelt.MinX = _Experiment.Program.GetMeltingMinTemp();
				UCChartRawMelt.MaxX = _Experiment.Program.GetMeltingMaxTemp();
			}
			if (tabItemRawCurve.Visibility == Visibility.Visible)
			{
				tabItemRawCurve.IsSelected = true;
			}
			else if (tabItemRawMeltCurve.Visibility == Visibility.Visible)
			{
				tabItemRawMeltCurve.IsSelected = true;
			}
			UCChartRawMelt.Targets = ((tabItemRawMeltCurve.Visibility == Visibility.Visible) ? UCWellPlateRun.WellTargets : null);
			RefreshTabControlItem(TabControlCurve);
		}

		public void RefrehSelectedWell()
		{
			UCWellPlateRun.RefreshSelectedWells(true);
			RefreshChartSample();
		}

		public void DisplayChannel(bool[] channelDisplay, bool all)
		{
			UCWellInfoRun.DisplayChannel(channelDisplay, all);
		}

		public void SetRunStatus()
		{
			if (_Experiment.Device.RunState == RunningState.Running || _Experiment.Device.RunState == RunningState.WaitingRunning)
			{
				tabItemStatus.IsSelected = true;
				if (tabItemRawCurve.Visibility == Visibility.Visible)
				{
					tabItemRawCurve.IsSelected = true;
				}
				else if (tabItemRawMeltCurve.Visibility == Visibility.Visible)
				{
					tabItemRawMeltCurve.IsSelected = true;
				}
			}
		}

		public void RefreshWellInfoData()
		{
			UCWellInfoRun.ReloadGridData();
			UCWellInfoRun.AutoSizeColumnSize();
		}

		public void RefreshChartInfo(bool refreshData = true)
		{
			if (!_Experiment.HasData())
			{
				return;
			}
			List<Sample> list = null;
			List<SampleTargetItem> list2 = new List<SampleTargetItem>();
			List<int> displayChannelNo = UCWellInfoRun.GetDisplayChannelNo();
			switch (CurveMaxYMode)
			{
			default:
				return;
			case ECurveMaxYMode.AllWells:
			case ECurveMaxYMode.SelectedChannel:
				list = (from s in _Experiment.CurrentSubset.Wells
					where s.Sample != null
					select s.Sample).ToList();
				foreach (Sample item in list)
				{
					list2.AddRange(item.Items);
				}
				break;
			case ECurveMaxYMode.SelectedProject:
				list = (from s in _Experiment.CurrentSubset.Wells
					where s.Sample != null && UCWellPlateRun.SelectedWells.Select((WellCell s1) => s1.Well.Project).Contains(s.Project)
					select s.Sample).ToList();
				foreach (Sample item2 in list)
				{
					list2.AddRange(item2.Items);
				}
				break;
			case ECurveMaxYMode.SelectedWells:
				list = (from s in UCWellPlateRun.SelectedWells
					where s.IsSelected && s.Well.Sample != null
					select s.Well.Sample).ToList();
				foreach (Sample item3 in list)
				{
					list2.AddRange(item3.Items);
				}
				break;
			case ECurveMaxYMode.SelectedSeries:
			{
				List<List<ChartData>> list3 = (from s in UCWellPlateRun.SelectedWells
					where s.IsSelected && s.Well.Sample != null
					select s.ChartData).ToList();
				foreach (List<ChartData> item4 in list3)
				{
					foreach (ChartData item5 in item4)
					{
						if (item5.IsVisible)
						{
							list2.Add(item5.SampleTargetItem);
						}
					}
				}
				break;
			}
			}
			double num = double.NaN;
			double num2 = double.NaN;
			double num3 = double.NaN;
			double num4 = double.NaN;
			double num5 = double.NaN;
			double num6 = double.NaN;
			foreach (SampleTargetItem item6 in list2)
			{
				if (CurveMaxYMode != ECurveMaxYMode.SelectedChannel || displayChannelNo.Contains(item6.ChannelNo - 1))
				{
					num3 = Utility.GetMin(num3, item6.Result.RawCurve.GetCurveMinY());
					num = Utility.GetMax(num, item6.Result.RawCurve.GetCurveMaxY());
					num4 = Utility.GetMin(num4, item6.Result.AMPCurve.GetCurveMinY());
					num2 = Utility.GetMax(num2, item6.Result.AMPCurve.GetCurveMaxY());
					if (item6.Result is MeltingTargetResult || item6.Result is HRMTargetResult)
					{
						num6 = Utility.GetMin(num6, ((MeltingTargetResult)item6.Result).RawMeltingCurve.GetCurveMinY());
						num5 = Utility.GetMax(num5, ((MeltingTargetResult)item6.Result).RawMeltingCurve.GetCurveMaxY());
					}
				}
			}
			CurveSetting curveSetting = ConfigSettings.GetInstance().CurveSetting;
			if (_Experiment.HasOneData())
			{
				if (!double.IsNaN(num))
				{
					UCChartRunRaw.MaxY = num * curveSetting.FirstDotTimes;
				}
			}
			else
			{
				if (UCChartRunRaw.MaxY == 1000.0)
				{
					double num7 = double.NaN;
					foreach (SampleTargetItem item7 in list2)
					{
						if ((CurveMaxYMode != ECurveMaxYMode.SelectedChannel || displayChannelNo.Contains(item7.ChannelNo - 1)) && item7.Result.RawCurve.CurvePoint.Count > 0)
						{
							num7 = Utility.GetMax(num7, item7.Result.RawCurve.CurvePoint[0].Y);
						}
					}
					if (!double.IsNaN(num7))
					{
						UCChartRunRaw.MaxY = num7 * curveSetting.FirstDotTimes;
					}
				}
				if (!double.IsNaN(num))
				{
					UCChartRunRaw.MaxY = ((num > UCChartRunRaw.MaxY) ? (num * curveSetting.MaxYTimes) : UCChartRunRaw.MaxY);
				}
				if (!double.IsNaN(num2))
				{
					UCChartRunAMP.MaxY = ((num2 > UCChartRunAMP.MaxY) ? (num2 * curveSetting.MaxYTimes) : UCChartRunAMP.MaxY);
				}
			}
			if (!double.IsNaN(num3))
			{
				UCChartRunRaw.MinY = ((num3 < 0.0) ? (num3 - (curveSetting.MaxYTimes - 1.0) * num) : 0.0);
			}
			if (!double.IsNaN(num4))
			{
				UCChartRunAMP.MinY = ((num4 < 0.0) ? (num4 - (curveSetting.MaxYTimes - 1.0) * num2) : 0.0);
			}
			if (!double.IsNaN(num6))
			{
				UCChartRawMelt.MinY = ((num6 < 0.0) ? (num6 - (curveSetting.MaxYTimes - 1.0) * num5) : 0.0);
			}
			if (!double.IsNaN(num5))
			{
				UCChartRawMelt.MaxY = num5 * curveSetting.MaxYTimes;
			}
			if (refreshData)
			{
				RefreshChartData();
			}
		}

		private void RefreshChartData()
		{
			UCChartRunRaw.RefreshAll = true;
			UCChartRunAMP.RefreshAll = true;
			UCChartRawMelt.RefreshAll = true;
			UCWellInfoRun.RefreshColumns();
			UCWellInfoRun.RaiseSelectionChanged();
			RefreshChartInfo(false);
		}

		public void InitChartInfo()
		{
			UCChartRunRaw.MinY = 0.0;
			UCChartRunRaw.MaxY = 1000.0;
			UCChartRunAMP.MinY = 0.0;
			UCChartRunAMP.MaxY = 1.0;
			UCChartRawMelt.MinY = 0.0;
			UCChartRawMelt.MaxY = 1000.0;
			ucTemperatureChart.Init();
			RefreshChartData();
		}

		private void WellPlateSelectionChanged_RoutedEvent(object sender, RoutedEventArgs e)
		{
			UCWellInfoRun.RefreshData();
			RefreshChartInfo(false);
		}

		private void OnSelectionChanged_RoutedEvent(object sender, RoutedEventArgs e)
		{
			if (TabControlCurve.SelectedItem == tabItemRawCurve)
			{
				UCChartRunRaw.RefreshSeries();
			}
			else if (TabControlCurve.SelectedItem == tabItemAMPCurve)
			{
				UCChartRunAMP.RefreshSeries();
			}
			else if (TabControlCurve.SelectedItem == tabItemRawMeltCurve)
			{
				UCChartRawMelt.RefreshSeries();
			}
			_NeedRefreshCurve[0] = TabControlCurve.SelectedItem != tabItemRawCurve;
			_NeedRefreshCurve[1] = TabControlCurve.SelectedItem != tabItemAMPCurve;
			_NeedRefreshCurve[2] = TabControlCurve.SelectedItem != tabItemRawMeltCurve;
		}

		private void TabControlCurve_SelectionChanged(object sender, SelectionChangedEventArgs e)
		{
			TabControl tabControl = sender as TabControl;
			if (tabControl != null)
			{
				if (UCChartRunRaw.RefreshAll || (_NeedRefreshCurve[0] && tabControl.SelectedItem == tabItemRawCurve))
				{
					_NeedRefreshCurve[0] = false;
					UCChartRunRaw.RefreshSeries();
				}
				if (UCChartRunAMP.RefreshAll || (_NeedRefreshCurve[1] && tabControl.SelectedItem == tabItemAMPCurve))
				{
					_NeedRefreshCurve[1] = false;
					UCChartRunAMP.RefreshSeries();
				}
				if (UCChartRawMelt.RefreshAll || (_NeedRefreshCurve[2] && tabControl.SelectedItem == tabItemRawMeltCurve))
				{
					_NeedRefreshCurve[2] = false;
					UCChartRawMelt.RefreshSeries();
				}
			}
		}

		private void RefreshTabControlItem(TabControlEx control)
		{
			control.RefreshTabItemStyle();
		}

		private void btnRestoreDefaultColor_Click(object sender, RoutedEventArgs e)
		{
			foreach (ChartData target in UCWellInfoRun.Targets)
			{
				target.SampleTargetItem.DeleteColor(_Experiment.ColorMode);
				target.SampleTargetItem.DeleteLinePointStyle(_Experiment.ColorMode);
			}
		}

		public void RefreshChartSample()
		{
			List<ChartData> source = UCWellPlateRun.WellTargets.ToList();
			spColor.Visibility = ((source.Where((ChartData s) => s.SampleTargetItem.HasCustomColor(_Experiment.ColorMode)).Count() > 0) ? Visibility.Collapsed : Visibility.Visible);
			btnRestoreDefaultColor.Visibility = ((spColor.Visibility == Visibility.Visible) ? Visibility.Collapsed : Visibility.Visible);
			if (spColor.Visibility == Visibility.Collapsed)
			{
				return;
			}
			spChannel.Visibility = ((_Experiment.ColorMode != 0) ? Visibility.Collapsed : Visibility.Visible);
			spSampleType.Visibility = ((_Experiment.ColorMode != EColorMode.Type) ? Visibility.Collapsed : Visibility.Visible);
			spRow.Visibility = ((_Experiment.ColorMode != EColorMode.Row) ? Visibility.Collapsed : Visibility.Visible);
			spColumn.Visibility = ((_Experiment.ColorMode != EColorMode.Column) ? Visibility.Collapsed : Visibility.Visible);
			spTarget.Visibility = ((_Experiment.ColorMode != EColorMode.Target) ? Visibility.Collapsed : Visibility.Visible);
			switch (_Experiment.ColorMode)
			{
			case EColorMode.Channel:
			{
				IList<int> list3 = source.Select((ChartData s) => s.SampleTargetItem.ChannelNo).Distinct().ToList();
				gridChannel1.Visibility = ((!list3.Contains(1)) ? Visibility.Collapsed : Visibility.Visible);
				gridChannel2.Visibility = ((!list3.Contains(2)) ? Visibility.Collapsed : Visibility.Visible);
				gridChannel3.Visibility = ((!list3.Contains(3)) ? Visibility.Collapsed : Visibility.Visible);
				gridChannel4.Visibility = ((!list3.Contains(4)) ? Visibility.Collapsed : Visibility.Visible);
				gridChannel5.Visibility = ((!list3.Contains(5)) ? Visibility.Collapsed : Visibility.Visible);
				gridChannel6.Visibility = ((!list3.Contains(6)) ? Visibility.Collapsed : Visibility.Visible);
				break;
			}
			case EColorMode.Type:
			{
				IList<SampleType> list5 = source.Select((ChartData s) => s.SampleTargetItem.SampleType).Distinct().ToList();
				gridHighPositive.Visibility = ((!list5.Contains(SampleType.HighPositive)) ? Visibility.Collapsed : Visibility.Visible);
				gridLowPositive.Visibility = ((!list5.Contains(SampleType.LowPositive)) ? Visibility.Collapsed : Visibility.Visible);
				gridNegative.Visibility = ((!list5.Contains(SampleType.Negative)) ? Visibility.Collapsed : Visibility.Visible);
				gridNTC.Visibility = ((!list5.Contains(SampleType.NTC)) ? Visibility.Collapsed : Visibility.Visible);
				gridQC.Visibility = ((!list5.Contains(SampleType.QC)) ? Visibility.Collapsed : Visibility.Visible);
				gridRetestSample.Visibility = ((!list5.Contains(SampleType.RetestSample)) ? Visibility.Collapsed : Visibility.Visible);
				gridStandard.Visibility = ((!list5.Contains(SampleType.Standard)) ? Visibility.Collapsed : Visibility.Visible);
				gridUnknow.Visibility = ((!list5.Contains(SampleType.Unknown)) ? Visibility.Collapsed : Visibility.Visible);
				break;
			}
			case EColorMode.Row:
			{
				IList<int> list2 = source.Select((ChartData s) => s.WellCell.RowIndex).Distinct().ToList();
				canvasRowA.Visibility = ((!list2.Contains(0)) ? Visibility.Collapsed : Visibility.Visible);
				canvasRowB.Visibility = ((!list2.Contains(1)) ? Visibility.Collapsed : Visibility.Visible);
				canvasRowC.Visibility = ((!list2.Contains(2)) ? Visibility.Collapsed : Visibility.Visible);
				canvasRowD.Visibility = ((!list2.Contains(3)) ? Visibility.Collapsed : Visibility.Visible);
				canvasRowE.Visibility = ((!list2.Contains(4)) ? Visibility.Collapsed : Visibility.Visible);
				canvasRowF.Visibility = ((!list2.Contains(5)) ? Visibility.Collapsed : Visibility.Visible);
				canvasRowG.Visibility = ((!list2.Contains(6)) ? Visibility.Collapsed : Visibility.Visible);
				canvasRowH.Visibility = ((!list2.Contains(7)) ? Visibility.Collapsed : Visibility.Visible);
				break;
			}
			case EColorMode.Column:
			{
				IList<int> list4 = source.Select((ChartData s) => s.WellCell.ColumnIndex).Distinct().ToList();
				canvasColumn1.Visibility = ((!list4.Contains(0)) ? Visibility.Collapsed : Visibility.Visible);
				canvasColumn2.Visibility = ((!list4.Contains(1)) ? Visibility.Collapsed : Visibility.Visible);
				canvasColumn3.Visibility = ((!list4.Contains(2)) ? Visibility.Collapsed : Visibility.Visible);
				canvasColumn4.Visibility = ((!list4.Contains(3)) ? Visibility.Collapsed : Visibility.Visible);
				canvasColumn5.Visibility = ((!list4.Contains(4)) ? Visibility.Collapsed : Visibility.Visible);
				canvasColumn6.Visibility = ((!list4.Contains(5)) ? Visibility.Collapsed : Visibility.Visible);
				canvasColumn7.Visibility = ((!list4.Contains(6)) ? Visibility.Collapsed : Visibility.Visible);
				canvasColumn8.Visibility = ((!list4.Contains(7)) ? Visibility.Collapsed : Visibility.Visible);
				canvasColumn9.Visibility = ((!list4.Contains(8)) ? Visibility.Collapsed : Visibility.Visible);
				canvasColumn10.Visibility = ((!list4.Contains(9)) ? Visibility.Collapsed : Visibility.Visible);
				canvasColumn11.Visibility = ((!list4.Contains(10)) ? Visibility.Collapsed : Visibility.Visible);
				canvasColumn12.Visibility = ((!list4.Contains(11)) ? Visibility.Collapsed : Visibility.Visible);
				break;
			}
			case EColorMode.Target:
			{
				List<Project> list = source.Select((ChartData s) => s.WellCell.Well.Project).Distinct().ToList();
				spTarget.Children.Clear();
				{
					foreach (Project item in list)
					{
						foreach (TargetItem item2 in item.Target.Items)
						{
							Rectangle rectangle = new Rectangle();
							rectangle.Margin = new Thickness(3.0, 0.0, 0.0, 0.0);
							rectangle.Height = 16.0;
							rectangle.Width = 16.0;
							rectangle.RadiusX = 10.0;
							rectangle.RadiusY = 10.0;
							rectangle.Fill = new SolidColorBrush(item2.Color);
							spTarget.Children.Add(rectangle);
							TextBlock textBlock = new TextBlock();
							textBlock.Margin = new Thickness(4.0, 3.0, 0.0, 0.0);
							textBlock.Text = ((list.Count == 1) ? item2.Name : (item.BasicInfo.Name + "_" + item2.Name));
							spTarget.Children.Add(textBlock);
						}
					}
					break;
				}
			}
			case EColorMode.Result:
				break;
			}
		}

		private void RestoreDefaultControlStatus()
		{
			RestoreDefaultControlSize();
			RestoreDefaultCheckBoxStatus();
		}

		private void RestoreDefaultControlSize()
		{
			cdWellRunLeft.Width = new GridLength(1.0, GridUnitType.Star);
			cdWellRunRight.Width = new GridLength(1.0, GridUnitType.Star);
			rdRunUp.Height = new GridLength(1.0, GridUnitType.Star);
			rdRunDown.Height = new GridLength(1.0, GridUnitType.Star);
		}

		private void RestoreDefaultCheckBoxStatus()
		{
			checkBoxWellInfoRun.IsChecked = false;
			checkBoxRunUp.IsChecked = false;
			checkBoxRunDown.IsChecked = false;
		}

		private void RestoreStarSize()
		{
			cdWellRunLeft.Width = new GridLength(cdWellRunLeft.ActualWidth, GridUnitType.Star);
			cdWellRunRight.Width = new GridLength(cdWellRunRight.ActualWidth, GridUnitType.Star);
			rdRunUp.Height = new GridLength(rdRunUp.ActualHeight, GridUnitType.Star);
			rdRunDown.Height = new GridLength(rdRunDown.ActualHeight, GridUnitType.Star);
		}

		private void RegisterCheckBoxEvent()
		{
			_StopRefresh = false;
		}

		private void UnRegisterCheckBoxEvent()
		{
			_StopRefresh = true;
		}

		private void checkBoxWellInfoRun_Checked(object sender, RoutedEventArgs e)
		{
			if (!_StopRefresh)
			{
				UnRegisterCheckBoxEvent();
				checkBoxRunUp.IsChecked = false;
				checkBoxRunDown.IsChecked = false;
				cdWellRunLeft.Width = new GridLength(1.0, GridUnitType.Star);
				cdWellRunRight.Width = new GridLength(cdWellRunRight.MinWidth);
				RegisterCheckBoxEvent();
			}
		}

		private void checkBoxWellInfoRun_Unchecked(object sender, RoutedEventArgs e)
		{
			if (!_StopRefresh)
			{
				UnRegisterCheckBoxEvent();
				RestoreDefaultControlStatus();
				RegisterCheckBoxEvent();
			}
		}

		private void checkBoxRunUp_Checked(object sender, RoutedEventArgs e)
		{
			if (!_StopRefresh)
			{
				UnRegisterCheckBoxEvent();
				checkBoxWellInfoRun.IsChecked = false;
				checkBoxRunDown.IsChecked = false;
				cdWellRunLeft.Width = new GridLength(cdWellRunLeft.MinWidth);
				cdWellRunRight.Width = new GridLength(1.0, GridUnitType.Star);
				rdRunUp.Height = new GridLength(1.0, GridUnitType.Star);
				rdRunDown.Height = new GridLength(rdRunDown.MinHeight);
				RegisterCheckBoxEvent();
			}
		}

		private void checkBoxRunUp_Unchecked(object sender, RoutedEventArgs e)
		{
			if (!_StopRefresh)
			{
				UnRegisterCheckBoxEvent();
				RestoreDefaultControlStatus();
				RegisterCheckBoxEvent();
			}
		}

		private void checkBoxRunDown_Checked(object sender, RoutedEventArgs e)
		{
			if (!_StopRefresh)
			{
				UnRegisterCheckBoxEvent();
				checkBoxWellInfoRun.IsChecked = false;
				checkBoxRunUp.IsChecked = false;
				cdWellRunLeft.Width = new GridLength(cdWellRunLeft.MinWidth);
				cdWellRunRight.Width = new GridLength(1.0, GridUnitType.Star);
				rdRunUp.Height = new GridLength(rdRunUp.MinHeight);
				rdRunDown.Height = new GridLength(1.0, GridUnitType.Star);
				RegisterCheckBoxEvent();
			}
		}

		private void checkBoxRunDown_Unchecked(object sender, RoutedEventArgs e)
		{
			if (!_StopRefresh)
			{
				UnRegisterCheckBoxEvent();
				RestoreDefaultControlStatus();
				RegisterCheckBoxEvent();
			}
		}

		private void gridSplitter_PreviewMouseDown(object sender, MouseButtonEventArgs e)
		{
			UnRegisterCheckBoxEvent();
			RestoreStarSize();
			RegisterCheckBoxEvent();
		}

		private void InitPCRProgramMenu()
		{
			object obj = base.Resources["menuProgram"];
			if (obj != null)
			{
				ucPCRProgram.AddCustomMenu(obj as ContextMenu);
			}
		}

		private void Command_AddCurrentSegmentCycles_CanExecute(object sender, CanExecuteRoutedEventArgs e)
		{
			e.CanExecute = _Experiment.CanAddOrDeleteSegment();
		}

		private void Command_AddCurrentSegmentCycles_Executed(object sender, ExecutedRoutedEventArgs e)
		{
			AddCurrentSegmengCycleWindow addCurrentSegmengCycleWindow = new AddCurrentSegmengCycleWindow();
			addCurrentSegmengCycleWindow.Owner = Utility.GetMainWindow();
			addCurrentSegmengCycleWindow.CurrentSegment = _Experiment.GetCurrentSegment();
			addCurrentSegmengCycleWindow.CurrentSegmentCycle = _Experiment.GetCurrentSegmentCycle();
			if (addCurrentSegmengCycleWindow.ShowDialog() == true)
			{
				updataCurveFlag = false;
				if (!_Experiment.AddCurrentSegmentCycles(addCurrentSegmengCycleWindow.CurrentSegment, addCurrentSegmengCycleWindow.AddSegmentCycle))
				{
					MessageBox.Show(Utility.GetMessage("msg_modify_current_segment_failure"));
				}
				updataCurveFlag = true;
			}
		}

		private void Command_RemoveCurrentSegment_CanExecute(object sender, CanExecuteRoutedEventArgs e)
		{
			e.CanExecute = _Experiment.CanAddOrDeleteSegment();
		}

		private void Command_RemoveCurrentSegment_Executed(object sender, ExecutedRoutedEventArgs e)
		{
			string currentSegment = _Experiment.GetCurrentSegment();
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.AppendLine(Utility.GetMessage("msg_remove_current_segment"));
			stringBuilder.AppendLine(string.Format("{0}: {1}", Utility.GetMessage("current_segment"), currentSegment));
			stringBuilder.AppendLine(string.Format("{0}: {1}", Utility.GetMessage("current_cycle"), _Experiment.GetCurrentSegmentCycle()));
			if (MessageBox.Show(stringBuilder.ToString(), Utility.GetMessage("Warning"), MessageBoxButton.YesNo, MessageBoxImage.Exclamation, MessageBoxResult.No) == MessageBoxResult.Yes)
			{
				updataCurveFlag = false;
				if (!_Experiment.RemoveCurrentSegment(currentSegment))
				{
					MessageBox.Show(Utility.GetMessage("msg_modify_current_segment_failure"));
				}
				updataCurveFlag = true;
			}
		}

		public void SetWellInfoType(EWellInfoType type)
		{
			UCWellInfoRun.WellInfoType = type;
		}

		[DebuggerNonUserCode]
		[GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
		internal Delegate _CreateDelegate(Type delegateType, string handler)
		{
			return Delegate.CreateDelegate(delegateType, this, handler);
		}
	}
}
